// 树上三染色待续
#include <bits/stdc++.h> //
using namespace std;     //
const int MOD = 1e9 + 7;
int mem[200001][4];
int colors[2000001];
vector<int> edge[200001];
void dfs(int x, int father) {

  for (int child : edge[x]) {
    if (child == father)
      continue; // 避免回到父节点
    dfs(child, x);
    for (int color = 1; color <= 3; color++) {
      int sum = 0;
      for (int k = 1; k <= 3; k++) {
        if (color != k) {
          sum = (sum + mem[child][k]) % MOD;
        }
      }
      if (mem[x][color] != 0)
        mem[x][color] = (mem[x][color] * sum) % MOD;
    }
  }
}
int main() {
  int n, k;
  cin >> n >> k;
  memset(mem, -1, sizeof(mem));
  for (int i = 2; i <= n; i++) {
    int p;
    cin >> p;
    edge[p].push_back(i);
  }
  for (int i = 1; i <= k; i++) {
    cin >> colors[i];
    colors[i]++; // 颜色从1开始 : 1 ,2 ,3
    for (int j = 1; j <= 3; j++)
      if (colors[i] != j)
        mem[i][j] = 0; // 不能染的颜色，这个节点的mem为0
      else
        mem[i][j] = 1; // 能染的颜色，这个节点的mem为1
  }
  dfs(1, 0);
  // for (int i = 1; i <= n; i++) {
  //   cout << mem[i][1] << " " << mem[i][2] << " " << mem[i][3] << endl;
  // }
  if (colors[1] == 0) // 根节点未指定颜色
    cout << (mem[1][1] + mem[1][2] + mem[1][3]) % MOD;
  else
    cout << mem[1][colors[1]] % MOD;
  return 0;
}
